﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text;

namespace Theosoft.Mobile.LibService
{
    public class SendSMSTask : NetworkService
    {
        internal const string SendSMSURL = "sendsms.php";
        //internal const string CityListURL = "smslog.php";
        public bool SendSMS(string cellNo, string smsMsg, string pushToken = "")
        {
            if (String.IsNullOrEmpty(cellNo) || String.IsNullOrEmpty(smsMsg))
            {
                return false;
            }
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("tar={0}&msg=", cellNo);
            byte[] buffer = AESEncrypt.Encrypt(Encoding.UTF8.GetBytes(smsMsg), ENCRYPTKEY, ENCRYPTIV);
            sb.Append(Convert.ToBase64String(buffer));
            sb.AppendFormat("&tkn={0}", pushToken);
            dac.http_post(APIurl + SendSMSURL, sb.ToString());

            return true;
        }

        protected override void onProcessResponse(byte[] buffer)
        {
            string result = Encoding.UTF8.GetString(buffer, 0, buffer.Length);

            this.Completed.Invoke(this, new objEventArgs(result));
        }
    }
}
